package com.jintian.smart.base.expression.fn;

import com.jintian.smart.kernel.common.context.ContextHolder;
import com.jintian.smart.kernel.core.annotation.beetl.BeetlFunction;
import org.beetl.core.Context;
import org.beetl.core.Function;

@BeetlFunction(code = "loginName")
public class LoginNameFunction implements Function {
    @Override
    public Object call(Object[] paras, Context ctx) {
        if (ContextHolder.getUserId() == null) {
            Object defaultValue = paras.length > 1 ? paras[1] : null;
            return defaultValue;
        }

        return ContextHolder.getName();
    }
}
